/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dk.rofl.modes;

import dk.eleit.input.SaveLoadManager;

/**
 *
 * @author menderleit
 */
public abstract class ModeSwitcher {

    // Constants for setting the Mode.
    public static final int MODE_NONE = 0;
    public static final int MODE_TITLE = 1;
    public static final int MODE_GAME = 2;
    public static final int MODE_LOADGAME = 3;
    // Mode switching variables.
    private static Mode newMode;
    private static Mode currentMode;
    private static boolean switchMode;
    private static SaveLoadManager slm;

    // Initialize the ModeSwitcher.
    public static void init() {

        newMode = null;
        currentMode = new GameMode();
        switchMode = false;
    }

    // Set a new mode that we want to switch to.
    public static void setNewMode(int mode) {
        slm = new SaveLoadManager();
        switch (mode) {
            case MODE_TITLE:
                newMode = new TitleMode();
                break;
            case MODE_GAME:
                newMode = new GameMode();
                break;
            case MODE_LOADGAME:
                if (slm.load() != null) {
                    newMode = new GameMode(slm.load());
                } else {
                    newMode = new GameMode();
                }
                break;
        }
        switchMode = true;
    }

    // Returns the mode that we are currently in.
    public static Mode getCurrentMode() {
        return currentMode;
    }

    // Returns True if we want to switch to a new mode.
    public static boolean isNewModeSet() {
        return switchMode;
    }

    // Switches to the new mode and returns the appropriate Mode object.
    public static Mode switchMode() {

        // We no longer want to switch modes, since we are doing it now.
        switchMode = false;

        // Clean up after the current Mode.
        currentMode.exit();

        // Set the current mode to the new Mode.
        currentMode = newMode;
        currentMode.setSwitchLock(true);

        // Return the Mode object.
        return currentMode;
    }
}
